package org.dromara.job.processors;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.common.json.utils.JsonUtils;
import org.dromara.patrol.api.RemotePatrolSnapLogicService;
import org.dromara.patrol.api.domain.bo.RemotePatrolSnapBo;
import org.springframework.stereotype.Component;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;

/**
 * 抓拍巡店定时rpc调度视频流抽帧服务
 */
@Slf4j
@Component
public class PatrolSnapFrameExtractionProcessor implements BasicProcessor {

    @DubboReference(timeout = 15000)
    private RemotePatrolSnapLogicService remotePatrolSnapLogicService;

    @Override
    public ProcessResult process(TaskContext context) throws Exception {
        log.info("PatrolSnapFrameExtractionProcessor 开始执行 params={}", context.getJobParams());
        // 获取任务参数：抓拍计划id，设备id，门店id
        RemotePatrolSnapBo remotePatrolSnapBo = getRemotePatrolSnap(context);
        // 调用业务服务，处理业务
        Boolean result = remotePatrolSnapLogicService.processBusinessLogic(remotePatrolSnapBo);
        return new ProcessResult(result, "PatrolSnapFrameExtractionProcessor 执行完成");
    }

    private RemotePatrolSnapBo getRemotePatrolSnap(TaskContext taskContext) {
        return JsonUtils.parseObject(taskContext.getJobParams(), RemotePatrolSnapBo.class);
    }
}
